package com.example.contrller.appinfo;

import com.alibaba.fastjson.JSON;
import com.example.biz.AppInfo.AppInfobiz;
import com.example.biz.DevUser.IDevUserbiz;
import com.example.pojo.AppInfo;
import com.example.pojo.DataDictionary;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/info")
public class AppInfoController {
    @Resource
    private AppInfobiz biz;

    @Resource
    private IDevUserbiz biz1;

    @RequestMapping("infoShow")
    public String findInfo(Model model){
        List<AppInfo> list=biz.page();
        model.addAttribute("page",list);
        return "dev/Audit";
    }

    @RequestMapping("infoMo")
    public String  findAppInfoMo(AppInfo appInfo,Model model){
        List<AppInfo> list=biz.findAppInfoMo(appInfo);
        model.addAttribute("page",list);
        return "dev/Audit";
    }

    @RequestMapping("findAppInfoDele/{id}")
    public String  findAppInfoDele(@PathVariable("id") Integer id){
        biz.findAppInfoDele(id);
        return "redirect:/info/infoShow";
    }

    @PostMapping("findAppInfoAdd")
    public String findAppInfoAdd(AppInfo appInfo){
    biz.findAppInfoAdd(appInfo);
    return "redirect:/info/infoShow";
    }

    @GetMapping(value = "/status",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String role(){
        List<DataDictionary> list=biz.findAppCateId();
        for (DataDictionary category : list) {
            System.out.println(category);
        }
        String duan= JSON.toJSONString(list);
        System.out.println(duan);
        return duan;
    }


    @RequestMapping("AppInfoUpdate/{id}")
    public String   findId(@PathVariable("id") Integer id,Model model){
        AppInfo appInfo=biz.findId(id);
        model.addAttribute("appInfo",appInfo);
    return "dev/AppInfoUpdate";
    }

    @RequestMapping("AppInfoaa")
    public String AppInfoaa(AppInfo appInfo){
        biz.findAppInfoUpdate(appInfo);
        return "redirect:/info/infoShow";
    }


    @RequestMapping("findAppInfoShow/{id}")
    public String   findIdShow(@PathVariable("id") Integer id,Model model){
        AppInfo appInfo=biz.findId(id);
        List<AppInfo>list=biz.findLishi(id);
        model.addAttribute("appInfo",appInfo);
        model.addAttribute("list",list);
        return "dev/AppInfoShow";
    }

    @RequestMapping("findStatus/{id}/{status}")
    public String findStatus(@PathVariable("status") Integer status,@PathVariable("id") Integer id){
        if (status==4){
            status=5;
        }else if(status==5){
            status=4;
        }else {
            System.out.println("编译报错！");
        }
        biz.findStatus(status,id);
        return "redirect:/info/infoShow";
    }

    @RequestMapping("findSz/{id}")
    public String findLiShi(@PathVariable("id") Integer id,Model model){
    List<AppInfo>list=biz.findLishi(id);
    model.addAttribute("list",list);
    return "dev/LishiAdd";
    }
}
